<?
class Debug_model extends CI_Model {

	public function __construct()
	{
		$this->load->database();
	}

	public function set_varieties() {
		$insert_data = array();

		$variety_usage = $this->input->post('variety_usage');
		$variety_name = $this->input->post('variety_name');
		$variety_area = $this->input->post('variety_area');
		$variety_usage_other = $this->input->post('variety_usage_other');

		foreach ($variety_usage as $key => $value) {
			if(is_int($key)) {
				$name = array_shift($variety_name);
				$area = array_shift($variety_area);
				if($value == 'other') {
					$usage = array_shift($variety_usage_other); 
				}
				else
					$usage = $value;
			}

			array_push($insert_data, array('name' => $name, 'area' => $area, 'usage' => $usage));
		}

		return $this->db->insert_batch('survey_varieties', $insert_data); 
	}
}
?>